package com.store.app.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.GoodsListBean;
import com.store.app.utils.MoneyUtil;

import java.util.List;

public class XiaoPiaoAdapter extends BaseAdapter  {
    private Context context;
    ViewHolder viewHolder = null;
    private List<GoodsListBean> list_goods;
    public XiaoPiaoAdapter(Context contextI, List<GoodsListBean> list_goods) {
        this.context = contextI;
        this.list_goods=list_goods;
    }
    @Override
    public int getCount() {
        return list_goods.size();
    }

    @Override
    public Object getItem(int position) {

        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_xiaopiao, null);
            viewHolder.tv_num = (TextView) convertView.findViewById(R.id.item_xiaopiao_num);
            viewHolder.tv_money = (TextView) convertView.findViewById(R.id.item_xiaopiao_money);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.item_xiaopiao_name);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if(!TextUtils.isEmpty(list_goods.get(position).getGoodsName())){
            viewHolder.tv_name.setText(list_goods.get(position).getGoodsName());
        }else{
            viewHolder.tv_name.setText("自定义");
        }
        viewHolder.tv_money.setText(MoneyUtil.formatMoney(list_goods.get(position).getPrice()));
        viewHolder.tv_num.setText("x"+list_goods.get(position).getCount()+"");

        return convertView;
    }


    class ViewHolder {
       private TextView tv_name;
       private TextView tv_num;
       private TextView tv_money;

    }


}
